import random
def guess_number_game():
    guessNumber = random.randint(1, 100)
    guessChange = 10
    guess = None # 初始化玩家的猜测
    tempChange = 10 # 初始化猜数字剩余的机会
    print("欢迎来到python猜游戏小课堂")

    while guessChange > 0:
        try:
            guess = int(input("请写出你的第一个猜的数字："))

            if guess < 1 or guess > 100:
                print("无效输入，请输入1-100之间的数字作为答案")
                continue # 判断输入的是否符合要求

            guessChange -= 1
            tempChange = guessChange - 1


            if guess == guessNumber:
                print("恭喜你，猜对啦！")
                break # 猜对后退出循环结束游戏

            elif guess > guessNumber:
                print(f"猜大了，还剩下{tempChange}次机会")
            else :
                print(f"猜小了,还剩下{tempChange}次机会")
            if guessChange == 0:
                print(f"很遗憾，你猜测的次数已经用完了，正确的数字是{guessNumber}。")

        except  ValueError:
            print("请输入一个有效的整数")

if __name__ == "__main__":
    guess_number_game()